package com.wowangz.cms.syscore.api;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.util.WebUtils;

import com.wowangz.cms.common.utils.SessionIDUtils;
import com.wowangz.cms.user.pojo.User;

public class AuthorityUtils {
	
	final protected static Logger logger = LoggerFactory.getLogger(AuthorityUtils.class);
	
	public static void isLogin(HttpServletRequest arg0, HttpServletResponse arg1, UserContext userContext)
	{

		
		boolean isAuthority = true;
		User sysUser = null;
	
		if(userContext != null) {
			sysUser = userContext.getLoginUser();

//			//判断SessionIDUtils是否还存在SessionID
//			if(!SessionIDUtils.isExist(arg0.getSession().getId())){
//				isAuthority = false;
//			}
			
			//判断用户上下文中的用户是否为空
			if(sysUser == null) {
				isAuthority = false;
			}
		}
		else {
			
			isAuthority = false;
			
		}
		
		if(isAuthority == false) {
			
			WebUtils.setSessionAttribute(arg0, "userContext", null);
			try {
				arg1.sendRedirect(arg0.getContextPath() + "/sessionOut.jsp");
				return;
			} catch (IOException e) {
				e.printStackTrace();
			}
		
		}
	
	}

}
